package com.xhwl.logistics.bo.input;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.logistics.constant.VehicleConstant;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class PageBO {

    private Integer pageNumber;

    private Integer pageSize;

    private String sortColumn;

    private String sortDirection;

    public Page<?> toPage() {
        Page<?> page = new Page<>();
        page.setCurrent(pageNumber);
        page.setSize(pageSize);

        if (VehicleConstant.SORT_DIRECTION_ASC.equals(sortDirection)) {
            page.setOrders(OrderItem.ascs(sortColumn));
        }
        if (VehicleConstant.SORT_DIRECTION_DESC.equals(sortDirection)) {
            page.setOrders(OrderItem.descs(sortColumn));
        }
        return page;
    }

    public <T> Page<T> toPage(Class<T> clazz) {
        Page<T> page = new Page<>();
        page.setCurrent(pageNumber);
        page.setSize(pageSize);

        if (VehicleConstant.SORT_DIRECTION_ASC.equals(sortDirection)) {
            page.setOrders(OrderItem.ascs(sortColumn));
        }
        if (VehicleConstant.SORT_DIRECTION_DESC.equals(sortDirection)) {
            page.setOrders(OrderItem.descs(sortColumn));
        }
        return page;
    }

}
